home *** CD-ROM | disk | FTP | other *** search
- # include "stdio.h"
- # define U(x) x
- # define NLSTATE yyprevious=YYNEWLINE
- # define BEGIN yybgin = yysvec + 1 +
- # define INITIAL 0
- # define YYLERR yysvec
- # define YYSTATE (yyestate-yysvec-1)
- # define YYOPTIM 1
- # define YYLMAX 200
- # define output(c) putc(c,yyout)
- # define input() (((yytchar=yysptr>yysbuf?U(*--yysptr):getc(yyin))==10?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)
- # define unput(c) {yytchar= (c);if(yytchar=='\n')yylineno--;*yysptr++=yytchar;}
- # define yymore() (yymorfg=1)
- # define ECHO fprintf(yyout, "%s",yytext)
- # define REJECT { nstr = yyreject(); goto yyfussy;}
- int yyleng; extern char yytext[];
- int yymorfg;
- extern char *yysptr, yysbuf[];
- int yytchar;
- FILE *yyin ={stdin}, *yyout ={stdout};
- extern int yylineno;
- struct yysvf {
- struct yywork *yystoff;
- struct yysvf *yyother;
- int *yystops;};
- struct yysvf *yyestate;
- extern struct yysvf yysvec[], *yybgin;
- /*
- * import_export_mailrc
- *
- * This program is used to convert .mailrc mail configuration file to
- * .mailalias NeXTMail configuration files and back.
- *
- * Copyright (C) 1991 Roberto Di Cosmo
- *
- * Everyone is granted permission to copy, modify and redistribute
- * this file, as far as this notice is preserved on all copies.
- *
- * Written by:
- * Roberto Di Cosmo <dicosmo@dmi.ens.fr>
- * Dipartimento di Informatica LIENS
- * Universita' di Pisa Ecole Normale Superieure
- * Corso Italia, 40 45, Rue d'Ulm
- * Pisa ITALY Paris FRANCE
- *
- * $Header: /users/formel2/dicosmo/Projects/SAVEFROMMAIL/RCS/import_export_mailrc.l,v 1.2 92/05/06 14:20:25 dicosmo Exp $
- *
- * $Log: import_export_mailrc.l,v $
- * Revision 1.2 92/05/06 14:20:25 dicosmo
- * Conversion engine il Lex. Common body for command line
- * and NeXTStep application.
- *
- *
- */
-
- int skipblanks = 1;
- char *aliasname = "";
- char *groupbody = "";
- char *aliasbody = "";
- char *aliases = "";
- char *tmp = "";
- #define YES 1
- #define NO 0
- int is_group = NO;
- int is_balanced = YES;
- int l;
- # define NrmImp 2
- # define AName 4
- # define Addr0 6
- # define Addr1 8
- # define Addr2 10
- # define Sep 12
- # define NrmExp 14
- # define Copy 16
- # define UserAlias 18
- # define UserAddr 20
-
- # define YYNEWLINE 10
- int yylex(){
- int nstr; extern int yyprevious;
- while((nstr = yylook()) >= 0)
- yyfussy: switch(nstr){
- case 0:
- if(yywrap()) return(0); break;
- case 1:
- {BEGIN AName;}
- break;
- case 2:
- ;
- break;
- case 3:
- {strcpy(aliasname,yytext); BEGIN Addr0;}
- break;
- case 4:
- {printf("***Missing alias name ...");}
- break;
- case 5:
- {strcpy(tmp,"");BEGIN Addr1;}
- break;
- case 6:
- {BEGIN Addr2;}
- break;
- case 7:
- {printf("***Missing body of alias %s\n",aliasname);}
- break;
- case 8:
- ;
- break;
- case 9:
- {strcat(tmp,yytext);}
- break;
- case 10:
- {BEGIN Sep;}
- break;
- case 11:
- {printf("***Address %s of alias %s is not properly balanced ...",aliasbody,aliasname);}
- break;
- case 12:
- ;
- break;
- case 13:
- {strcpy(tmp,yytext); BEGIN Sep;}
- break;
- case 14:
- {printf("***Missing alias body of %s...",aliasname);}
- break;
- case 15:
- {if (is_group == YES) {strcat(groupbody,tmp);committ_import_group();is_group = NO;}
- else {strcpy(aliasbody,tmp); committ_import_alias();}; BEGIN NrmImp;}
- break;
- case 16:
- {strcat(groupbody,tmp); is_group = YES; strcat(groupbody,"\, "); strcpy(tmp,"");BEGIN Addr1;}
- break;
- case 17:
- {strcat(groupbody,tmp); is_group = YES; strcat(groupbody,"\, "); BEGIN Addr2;}
- break;
- case 18:
- ;
- break;
- case 19:
- {BEGIN UserAlias;}
- break;
- case 20:
- {strncat(aliasname, yytext, yyleng-1); BEGIN Copy;}
- break;
- case 21:
- {committ_export_alias(); BEGIN NrmExp;}
- break;
- case 22:
- {strcat(aliasbody,yytext);}
- break;
- case 23:
- {strcat(aliasname,"_");}
- break;
- case 24:
- {BEGIN UserAddr;}
- break;
- case 25:
- {strcat(aliasname,yytext);}
- break;
- case 26:
- {printf("***Missing address of alias %s\n",aliasname);}
- break;
- case 27:
- ;
- break;
- case 28:
- {committ_export_alias(); BEGIN NrmExp;}
- break;
- case 29:
- {committ_export_alias(); BEGIN UserAlias;}
- break;
- case 30:
- {strcat(aliasbody,yytext);}
- break;
- case 31:
- {printf("***Incomplete %s address in alias %s\n",aliasbody,aliasname);}
- break;
- case -1:
- break;
- default:
- fprintf(yyout,"bad switch yylook %d",nstr);
- } return(0); }
- /* end of yylex */
-
-
- /*
- * Commit group alias for IMPORT
- */
-
- committ_import_group()
- {
- printf("%s: %s\n", aliasname, groupbody);
- resetvars();
- }
-
-
- /*
- * Commit user alias for IMPORT
- */
-
- committ_import_alias()
- {
- sprintf(tmp, "%s <%s>,", aliasname, aliasbody);
- strcat(aliases, tmp);
- resetvars();
- }
-
- /*
- * Commit alias for EXPORT
- */
-
- committ_export_alias()
- {
- printf("alias %s %s\n", aliasname, aliasbody);
- resetvars();
- }
-
- /*
- * this are the *REAL* conversion loops, that are exported...
- */
-
- void import_mailrc()
- {
- allocfields();
- initvars();
- BEGIN NrmImp;
- while (yylex()) {};
- if ((l = strlen(aliases)) > 0) aliases[strlen(aliases)-1]=NULL;
- printf("Private Users: %s\n", aliases);
- }
-
- void export_mailrc()
- {
- allocfields();
- initvars();
- BEGIN NrmExp;
- while (yylex()) {};
- }
-
- /* main()
- {import_mailrc();}
- */
-
- allocfields()
- { /* allocate memory for parser variables */
- tmp = malloc(6000);
- aliasname = malloc(80);
- aliasbody = malloc(1000);
- groupbody = malloc(10000);
- aliases = malloc(50000); /* contains *ALL* the group aliases!!!!! */
- }
-
- initvars()
- {
- (void)strcpy(aliases,"");
- resetvars();
- }
-
- resetvars()
- {
- (void)strcpy(tmp, "" );
- (void)strcpy(aliasname, "" );
- (void)strcpy(aliasbody, "" );
- (void)strcpy(groupbody, "" );
- }
- int yyvstop[] ={
- 0,
-
- 6,
- 0,
-
- 6,
- 0,
-
- 6,
- 0,
-
- 6,
- 0,
-
- 6,
- 0,
-
- 6,
- 0,
-
- 6,
- 0,
-
- 6,
- 0,
-
- 6,
- 0,
-
- 6,
- 0,
-
- 6,
- 0,
-
- 6,
- 0,
-
- 6,
- 0,
-
- 6,
- 0,
-
- 6,
- 0,
-
- 6,
- 0,
-
- 6,
- 0,
-
- 6,
- 0,
-
- 6,
- 0,
-
- 6,
- 0,
-
- 6,
- 0,
-
- 6,
- 0,
-
- 2,
- 0,
-
- 2,
- 0,
-
- 2,
- 0,
-
- 3,
- 0,
-
- 4,
- 0,
-
- 7,
- 0,
-
- 6,
- 7,
- 0,
-
- 5,
- 7,
- 0,
-
- 9,
- 0,
-
- 8,
- 0,
-
- 11,
- 0,
-
- 10,
- 0,
-
- 13,
- 0,
-
- 12,
- 0,
-
- 14,
- 0,
-
- 17,
- 0,
-
- 15,
- 0,
-
- 18,
- 0,
-
- 18,
- 0,
-
- 22,
- 0,
-
- 22,
- 0,
-
- 21,
- 0,
-
- 25,
- 0,
-
- 23,
- 25,
- 0,
-
- 26,
- 0,
-
- 24,
- 25,
- 0,
-
- 30,
- 0,
-
- 27,
- 30,
- 0,
-
- 31,
- 0,
-
- 29,
- 30,
- 0,
-
- 6,
- 0,
-
- 5,
- 0,
-
- 16,
- 0,
-
- 20,
- 0,
-
- 23,
- 0,
-
- 24,
- 0,
-
- 27,
- 0,
-
- 29,
- 0,
-
- 28,
- 0,
-
- 1,
- 0,
-
- 19,
- 20,
- 0,
-
- 19,
- 0,
- 0};
- # define YYTYPE unsigned char
- struct yywork { YYTYPE verify, advance; } yycrank[] ={
- 0,0, 0,0, 3,23, 0,0,
- 0,0, 0,0, 5,26, 0,0,
- 0,0, 7,28, 3,23, 3,0,
- 4,24, 4,0, 5,0, 5,27,
- 6,0, 7,29, 7,28, 9,31,
- 13,38, 13,39, 11,35, 15,40,
- 24,55, 42,42, 0,0, 9,32,
- 9,33, 0,0, 11,36, 11,37,
- 16,41, 0,0, 0,0, 26,0,
- 26,0, 5,0, 0,0, 6,0,
- 16,42, 16,41, 0,0, 13,38,
- 0,0, 3,23, 15,40, 24,55,
- 17,44, 5,26, 76,77, 10,0,
- 7,28, 0,0, 12,0, 13,38,
- 17,45, 17,46, 26,0, 3,23,
- 0,0, 8,30, 9,0, 5,26,
- 20,50, 11,0, 7,28, 10,0,
- 7,30, 10,34, 12,0, 18,44,
- 12,0, 18,44, 22,54, 16,41,
- 9,31, 19,47, 9,0, 11,35,
- 9,34, 11,0, 38,60, 11,0,
- 21,51, 19,48, 19,49, 82,83,
- 0,0, 16,0, 32,32, 17,45,
- 21,52, 21,53, 36,36, 29,58,
- 31,0, 31,0, 45,63, 45,46,
- 4,25, 48,64, 35,0, 35,0,
- 69,71, 17,44, 52,66, 17,44,
- 57,69, 17,44, 25,57, 16,43,
- 24,56, 32,32, 41,41, 43,62,
- 62,70, 36,36, 29,58, 31,0,
- 19,47, 45,63, 41,41, 41,41,
- 48,64, 35,0, 70,72, 21,51,
- 71,73, 52,66, 72,74, 31,0,
- 74,75, 45,63, 19,47, 73,73,
- 19,50, 35,0, 54,67, 54,68,
- 75,76, 21,51, 77,78, 32,34,
- 78,79, 21,54, 29,59, 31,0,
- 79,80, 31,0, 80,81, 81,82,
- 48,65, 35,0, 83,84, 35,0,
- 0,0, 41,41, 73,73, 0,0,
- 0,0, 54,67, 0,0, 0,0,
- 0,0, 0,0, 0,0, 0,0,
- 0,0, 0,0, 0,0, 41,61,
- 0,0, 54,67, 0,0, 0,0,
- 0,0, 83,84, 0,0, 0,0,
- 0,0};
- struct yysvf yysvec[] ={
- 0, 0, 0,
- yycrank+0, 0, yyvstop+1,
- yycrank+0, 0, yyvstop+3,
- yycrank+-1, 0, yyvstop+5,
- yycrank+-3, yysvec+3, yyvstop+7,
- yycrank+-5, 0, yyvstop+9,
- yycrank+-7, yysvec+5, yyvstop+11,
- yycrank+-8, 0, yyvstop+13,
- yycrank+-1, yysvec+7, yyvstop+15,
- yycrank+-18, 0, yyvstop+17,
- yycrank+-7, yysvec+9, yyvstop+19,
- yycrank+-21, 0, yyvstop+21,
- yycrank+-10, yysvec+11, yyvstop+23,
- yycrank+11, 0, yyvstop+25,
- yycrank+0, yysvec+13, yyvstop+27,
- yycrank+14, 0, yyvstop+29,
- yycrank+-31, 0, yyvstop+31,
- yycrank+-47, 0, yyvstop+33,
- yycrank+-11, yysvec+17, yyvstop+35,
- yycrank+-76, 0, yyvstop+37,
- yycrank+-4, yysvec+19, yyvstop+39,
- yycrank+-83, 0, yyvstop+41,
- yycrank+-12, yysvec+21, yyvstop+43,
- yycrank+0, 0, yyvstop+45,
- yycrank+15, 0, yyvstop+47,
- yycrank+2, 0, yyvstop+49,
- yycrank+-26, yysvec+5, yyvstop+51,
- yycrank+0, 0, yyvstop+53,
- yycrank+0, 0, yyvstop+55,
- yycrank+86, 0, yyvstop+57,
- yycrank+0, 0, yyvstop+60,
- yycrank+-87, yysvec+9, yyvstop+63,
- yycrank+81, 0, yyvstop+65,
- yycrank+0, 0, yyvstop+67,
- yycrank+0, 0, yyvstop+69,
- yycrank+-93, yysvec+11, yyvstop+71,
- yycrank+85, 0, yyvstop+73,
- yycrank+0, 0, yyvstop+75,
- yycrank+22, yysvec+13, yyvstop+77,
- yycrank+0, 0, yyvstop+79,
- yycrank+0, yysvec+15, yyvstop+81,
- yycrank+-113, 0, 0,
- yycrank+-16, yysvec+41, yyvstop+83,
- yycrank+-1, yysvec+41, 0,
- yycrank+0, 0, yyvstop+85,
- yycrank+89, 0, yyvstop+87,
- yycrank+0, 0, yyvstop+89,
- yycrank+0, 0, yyvstop+91,
- yycrank+92, 0, yyvstop+93,
- yycrank+0, 0, yyvstop+96,
- yycrank+0, 0, yyvstop+98,
- yycrank+0, 0, yyvstop+101,
- yycrank+97, 0, yyvstop+103,
- yycrank+0, 0, yyvstop+106,
- yycrank+129, 0, yyvstop+108,
- yycrank+0, yysvec+24, 0,
- yycrank+0, yysvec+25, 0,
- yycrank+3, 0, 0,
- yycrank+0, yysvec+29, yyvstop+111,
- yycrank+0, 0, yyvstop+113,
- yycrank+0, 0, yyvstop+115,
- yycrank+0, 0, yyvstop+117,
- yycrank+-11, yysvec+41, 0,
- yycrank+0, yysvec+45, 0,
- yycrank+0, yysvec+48, yyvstop+119,
- yycrank+0, 0, yyvstop+121,
- yycrank+0, yysvec+52, yyvstop+123,
- yycrank+0, yysvec+54, yyvstop+125,
- yycrank+0, 0, yyvstop+127,
- yycrank+7, 0, 0,
- yycrank+-8, yysvec+41, 0,
- yycrank+13, 0, 0,
- yycrank+-33, yysvec+41, 0,
- yycrank+126, 0, yyvstop+129,
- yycrank+-16, yysvec+41, 0,
- yycrank+-39, yysvec+41, 0,
- yycrank+-18, yysvec+41, 0,
- yycrank+-57, yysvec+41, 0,
- yycrank+-29, yysvec+41, 0,
- yycrank+-47, yysvec+41, 0,
- yycrank+-36, yysvec+41, 0,
- yycrank+-36, yysvec+41, 0,
- yycrank+-29, yysvec+41, 0,
- yycrank+145, 0, yyvstop+131,
- yycrank+0, yysvec+83, yyvstop+134,
- 0, 0, 0};
- struct yywork *yytop = yycrank+177;
- struct yysvf *yybgin = yysvec+1;
- char yymatch[] ={
- 00 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
- 01 ,011 ,012 ,01 ,01 ,01 ,01 ,01 ,
- 01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
- 01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
- 011 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
- 01 ,01 ,01 ,01 ,',' ,01 ,01 ,01 ,
- 01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
- 01 ,01 ,':' ,01 ,',' ,01 ,',' ,01 ,
- 01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
- 01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
- 01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
- 01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
- 01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
- 01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
- 01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
- 01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
- 0};
- char yyextra[] ={
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,
- 0};
- /* ncform 4.1 83/08/11 */
-
- int yylineno =1;
- # define YYU(x) x
- # define NLSTATE yyprevious=YYNEWLINE
- char yytext[YYLMAX];
- struct yysvf *yylstate [YYLMAX], **yylsp, **yyolsp;
- char yysbuf[YYLMAX];
- char *yysptr = yysbuf;
- int *yyfnd;
- extern struct yysvf *yyestate;
- int yyprevious = YYNEWLINE;
- #if NeXT
- int yylook(){
- #else
- yylook(){
- #endif NeXT
- register struct yysvf *yystate, **lsp;
- register struct yywork *yyt;
- struct yysvf *yyz;
- int yych;
- struct yywork *yyr;
- # ifdef LEXDEBUG
- int debug;
- # endif
- char *yylastch;
- /* start off machines */
- # ifdef LEXDEBUG
- debug = 0;
- # endif
- if (!yymorfg)
- yylastch = yytext;
- else {
- yymorfg=0;
- yylastch = yytext+yyleng;
- }
- for(;;){
- lsp = yylstate;
- yyestate = yystate = yybgin;
- if (yyprevious==YYNEWLINE) yystate++;
- for (;;){
- # ifdef LEXDEBUG
- if(debug)fprintf(yyout,"state %d\n",yystate-yysvec-1);
- # endif
- yyt = yystate->yystoff;
- if(yyt == yycrank){ /* may not be any transitions */
- yyz = yystate->yyother;
- if(yyz == 0)break;
- if(yyz->yystoff == yycrank)break;
- }
- *yylastch++ = yych = input();
- tryagain:
- # ifdef LEXDEBUG
- if(debug){
- fprintf(yyout,"char ");
- allprint(yych);
- putchar('\n');
- }
- # endif
- yyr = yyt;
- if ( (int)yyt > (int)yycrank){
- yyt = yyr + yych;
- if (yyt <= yytop && yyt->verify+yysvec == yystate){
- if(yyt->advance+yysvec == YYLERR) /* error transitions */
- {unput(*--yylastch);break;}
- *lsp++ = yystate = yyt->advance+yysvec;
- goto contin;
- }
- }
- # ifdef YYOPTIM
- else if((int)yyt < (int)yycrank) { /* r < yycrank */
- yyt = yyr = yycrank+(yycrank-yyt);
- # ifdef LEXDEBUG
- if(debug)fprintf(yyout,"compressed state\n");
- # endif
- yyt = yyt + yych;
- if(yyt <= yytop && yyt->verify+yysvec == yystate){
- if(yyt->advance+yysvec == YYLERR) /* error transitions */
- {unput(*--yylastch);break;}
- *lsp++ = yystate = yyt->advance+yysvec;
- goto contin;
- }
- yyt = yyr + YYU(yymatch[yych]);
- # ifdef LEXDEBUG
- if(debug){
- fprintf(yyout,"try fall back character ");
- allprint(YYU(yymatch[yych]));
- putchar('\n');
- }
- # endif
- if(yyt <= yytop && yyt->verify+yysvec == yystate){
- if(yyt->advance+yysvec == YYLERR) /* error transition */
- {unput(*--yylastch);break;}
- *lsp++ = yystate = yyt->advance+yysvec;
- goto contin;
- }
- }
- if ((yystate = yystate->yyother) && (yyt= yystate->yystoff) != yycrank){
- # ifdef LEXDEBUG
- if(debug)fprintf(yyout,"fall back to state %d\n",yystate-yysvec-1);
- # endif
- goto tryagain;
- }
- # endif
- else
- {unput(*--yylastch);break;}
- contin:
- # ifdef LEXDEBUG
- if(debug){
- fprintf(yyout,"state %d char ",yystate-yysvec-1);
- allprint(yych);
- putchar('\n');
- }
- # endif
- ;
- }
- # ifdef LEXDEBUG
- if(debug){
- fprintf(yyout,"stopped at %d with ",*(lsp-1)-yysvec-1);
- allprint(yych);
- putchar('\n');
- }
- # endif
- while (lsp-- > yylstate){
- *yylastch-- = 0;
- if (*lsp != 0 && (yyfnd= (*lsp)->yystops) && *yyfnd > 0){
- yyolsp = lsp;
- if(yyextra[*yyfnd]){ /* must backup */
- while(yyback((*lsp)->yystops,-*yyfnd) != 1 && lsp > yylstate){
- lsp--;
- unput(*yylastch--);
- }
- }
- yyprevious = YYU(*yylastch);
- yylsp = lsp;
- yyleng = yylastch-yytext+1;
- yytext[yyleng] = 0;
- # ifdef LEXDEBUG
- if(debug){
- fprintf(yyout,"\nmatch ");
- sprint(yytext);
- fprintf(yyout," action %d\n",*yyfnd);
- }
- # endif
- return(*yyfnd++);
- }
- unput(*yylastch);
- }
- if (yytext[0] == 0 /* && feof(yyin) */)
- {
- yysptr=yysbuf;
- return(0);
- }
- yyprevious = yytext[0] = input();
- if (yyprevious>0)
- output(yyprevious);
- yylastch=yytext;
- # ifdef LEXDEBUG
- if(debug)putchar('\n');
- # endif
- }
- }
- #if NeXT
- int yyback(p, m)
- int *p;
- int m;
- #else
- yyback(p, m)
- int *p;
- #endif NeXT
- {
- if (p==0) return(0);
- while (*p)
- {
- if (*p++ == m)
- return(1);
- }
- return(0);
- }
- /* the following are only used in the lex library */
- #if NeXT
- int yyinput(){
- #else
- yyinput(){
- #endif NeXT
- return(input());
- }
- #if NeXT
- void yyoutput(c)
- int c;
- {
- output(c);
- }
- #else
- yyoutput(c)
- int c; {
- output(c);
- }
- #endif NeXT
- #if NeXT
- void yyunput(c)
- int c;
- {
- unput(c);
- }
- #else
- yyunput(c)
- int c; {
- unput(c);
- }
- #endif NeXT
-